package com.oa.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.oa.bean.IntegernalMail;
import com.oa.bean.Section;
import com.oa.bean.User;
import com.oa.service.IntegernalMailService;

@Controller
public class IntegernalMailController {

	@Resource
	IntegernalMailService integernalMailService;
	
	@RequestMapping("getListUser2")
	@ResponseBody
	public List<User> getListUser2(Integer deptno){
		List<User> list = integernalMailService.getListUser(deptno);
		return list;
	}
	
	@RequestMapping("sendEmail")
	public String sendEmail(IntegernalMail mail,HttpSession session){
		System.out.println(mail);
		Integer uid = (Integer) session.getAttribute("uid");
		mail.setEsend_id(uid);
		integernalMailService.sendMail(mail);
		return "redirect:Template/myemail.jsp";
	}
	
	@RequestMapping("getMyEmail")
	@ResponseBody
	public Map<String,Object> getMyEmail(Integer currentPage,HttpSession session){
		System.out.println(currentPage);
		Integer uid = (Integer) session.getAttribute("uid");
		System.out.println(uid);
		Map<String,Object> map = integernalMailService.getMyEmailList(currentPage, uid);
		return map;
	}
	
	@RequestMapping("getReceiveMyEmail")
	@ResponseBody
	public Map<String,Object> getReceiveMyEmail(Integer currentPage,HttpSession session){
		System.out.println(currentPage);
		String userName = (String) session.getAttribute("username");
		System.out.println(userName);
		Map<String,Object> map = integernalMailService.getReceiveEmail(currentPage, userName);
		return map;
	}
	
	@RequestMapping("getEmailByid")
	@ResponseBody
	public IntegernalMail getEmailByid(String rstate,Integer eid,HttpSession session){
		System.out.println(rstate);
		String userName = (String) session.getAttribute("username");
		IntegernalMail mail = integernalMailService.getEmailOne(rstate, eid, userName);
		return mail;
	}
	
	@RequestMapping("delectMySendEmail")
	@ResponseBody
	public String delectMySendEmail(String text){
		System.out.println(text);
		String result = integernalMailService.delectMySendMail(text);
		return result;
	}
	
	@RequestMapping("delectMyReceiveEmail")
	@ResponseBody
	public String delectMyReceiveEmail(String text,HttpSession session){
		String userName = (String) session.getAttribute("username");
		String result = integernalMailService.delectMyReceive(text, userName);
		return result;
	}
	
	@RequestMapping("getIdandName")
	@ResponseBody
	public List<Section> getIdandName(){
		List<Section> list = integernalMailService.getDeptnoandName();
		return list;
	}
	
}
